using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using VRCPRServer.Models;

namespace VRCPRServer.WLan
{
    public class SSIDM : INotifyPropertyChanged
    {
        private string _WiFiName = string.Empty;
        private string _WiFiPassWord = string.Empty;
        private bool _IsExpender = false;
        private string _StatePath = string.Empty;
        private string _Foreground = "#171717";
        private WlanNotificationCodeMsm _SSIDMsm = WlanNotificationCodeMsm.Disconnected;
        private WlanNotificationCodeAcm _SSIDAcm = WlanNotificationCodeAcm.Disconnected;
        private WiFiStatus _WiFiState = WiFiStatus.None;
        private string _ConnectText = string.Empty;
        private string _ConnectTip = string.Empty;
        private string _SSIDTip = string.Empty;
        private bool _IsConnected;
        private string _LocalStart = string.Empty;

        ///<summary>
        /// WiFi名称
        /// </summary>
        public string WiFiName
        {
            get { return _WiFiName; }
            set { _WiFiName = value; NotifyPropertyChanged(nameof(WiFiName)); }
        }

        /// <summary>
        /// WiFi密码
        /// </summary>
        public string WiFiPassWord
        {
            get { return _WiFiPassWord; }
            set { _WiFiPassWord = value; NotifyPropertyChanged(nameof(WiFiPassWord)); }
        }

        /// <summary>
        /// WiFi是否需要密码
        /// </summary>
        public bool IsExpender
        {
            get { return _IsExpender; }
            set { _IsExpender = value; NotifyPropertyChanged(nameof(IsExpender)); }
        }

        /// <summary>
        /// WiFi连接状态图标
        /// </summary>
        public string StatePath
        {
            get { return _StatePath; }
            set { _StatePath = value; NotifyPropertyChanged(nameof(StatePath)); }
        }

        /// <summary>
        /// WiFi连接状态时字体颜色
        /// </summary>
        public string Foreground
        {
            get { return _Foreground; }
            set { _Foreground = value; NotifyPropertyChanged(nameof(Foreground)); }
        }

        /// <summary>
        /// 尝试连接的状态
        /// </summary>
        public WlanNotificationCodeMsm SSIDMsm
        {
            get { return _SSIDMsm; }
            set
            {
                _SSIDMsm = value;
                NotifyPropertyChanged(nameof(SSIDMsm));
            }
        }

        /// <summary>
        /// 连接过程的状态
        /// </summary>
        public WlanNotificationCodeAcm SSIDAcm
        {
            get { return _SSIDAcm; }
            set
            {
                _SSIDAcm = value;
                if (value == WlanNotificationCodeAcm.ConnectionStart)
                    WiFiState = WiFiStatus.Connecting;

                if (value == WlanNotificationCodeAcm.ConnectionComplete && SSIDMsm == WlanNotificationCodeMsm.Connected)
                {
                    StatePath = @"/Resources;component\Controls\wLAN\Wlan_State.png";
                    Foreground = "#EE8321";
                    IsExpender = false;
                    WiFiState = WiFiStatus.Connected;
                }
                else
                {
                    StatePath = string.Empty;
                    Foreground = "#171717";
                    IsExpender = true;
                }

                NotifyPropertyChanged(nameof(SSIDAcm));
            }
        }

        // <summary>
        /// WiFi的状态
        /// </summary>
        public WiFiStatus WiFiState
        {
            get { return _WiFiState; }
            set
            {
                _WiFiState = value;
                NotifyPropertyChanged(nameof(WiFiState));
            }
        }

        /// <summary>
        /// 是否已保存链接
        /// </summary>
        public string ConnectText
        {
            get { return _ConnectText; }
            set
            {
                _ConnectText = value;
                NotifyPropertyChanged(nameof(ConnectText));
            }
        }

        /// <summary>
        /// 链接状态信息
        /// </summary>
        public string ConnectTip
        {
            get { return _ConnectTip; }
            set
            {
                _ConnectTip = value;
                NotifyPropertyChanged(nameof(ConnectTip));
            }
        }

        /// <summary>
        /// 当前WiFi信息（名称，信号强度，安全等）
        /// </summary>
        public string SSIDTip
        {
            get { return _SSIDTip; }
            set { _SSIDTip = value; NotifyPropertyChanged(nameof(SSIDTip)); }
        }

        /// <summary>
        /// 是否连接过(无需输入密码)
        /// </summary>
        public bool IsConnected
        {
            get { return _IsConnected; }
            set
            {
                _IsConnected = value;
                if (value)
                {
                    ConnectText = "连接过";
                }
                else
                {
                    ConnectText = string.Empty;
                }
                NotifyPropertyChanged(nameof(IsConnected));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string DotllDefaultAuthAlgorithm { get; set; }

        public string DotllDefaultCipherAlgorithm = string.Empty;
        public string NotConnectableReason = string.Empty;
        public bool Connectable = true;
        public int SignalQuality = 0;
        public WlanClient.WlanInterface Itrerface = null;
        public Wlan.WlanAvailableNetwork Network;


        public string LocalStart
        {
            get { return _LocalStart; }
            set { _LocalStart = value; NotifyPropertyChanged(nameof(LocalStart)); }
        }

        public SSIDM()
        {
            _SSIDMsm = WlanNotificationCodeMsm.Disconnected;
            _SSIDAcm = WlanNotificationCodeAcm.Disconnected;

            DotllDefaultAuthAlgorithm = string.Empty;
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        private void NotifyPropertyChanged( string propertyName)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

}
